package HLLib.base;

import java.util.Calendar;
import java.util.TimeZone;

import HLCode.HLClass;
import HLCode.HLClassManager;
import HLCode.HLClassManager_H;
import HLCode.HLLibObject;

public class HLTime extends HLLibObject {
    public HLClass GetClass(HLClassManager classManager) {
        return classManager.GetLibClass(HLClassManager_H.CLASS_GROUP_TYPE_LIB_BASE, HLClassManager_H.LIB_CLASS_BASE_Time);
    }

    public int GetInt(int index) {
        switch (index) {
        case 0: {
            return year;
        }
        case 1: {
            return month;
        }
        case 2: {
            return day;
        }
        case 3: {
            return hour;
        }
        case 4: {
            return minute;
        }
        case 5: {
            return second;
        }
        }
        return 0;
    }

    public void SetInt(int index, int value) {
        switch (index) {
        case 0: {
            year = value;
            return;
        }
        case 1: {
            month = value;
            return;
        }
        case 2: {
            day = value;
            return;
        }
        case 3: {
            hour = value;
            return;
        }
        case 4: {
            minute = value;
            return;
        }
        case 5: {
            second = value;
            return;
        }
        }
    }

    public int year;

    public int month;

    public int day;

    public int hour;

    public int minute;

    public int second;

    public final static HLLong CurrentMillisecond() {
        return new HLLong(System.currentTimeMillis());
    }

    public final static int CurrentSecond() {
        return (int) (System.currentTimeMillis() / 1000);
    }

    public final static HLString NowDate(char separator) {
        Calendar calendar = Calendar.getInstance(TimeZone.getDefault());
        StringBuffer sb = new StringBuffer();
        sb.//
        append(calendar.get(Calendar.YEAR)).//
                append(separator).//
                append(calendar.get(Calendar.MONTH) + 1).//
                append(separator).//
                append(calendar.get(Calendar.DATE));
        return new HLString(sb.toString());
    }

    public final static HLTime NowTime() {
        Calendar calendar = Calendar.getInstance(TimeZone.getDefault());

        HLTime time = new HLTime();
        time.year = calendar.get(Calendar.YEAR);
        time.month = calendar.get(Calendar.MONTH);
        time.day = calendar.get(Calendar.DAY_OF_MONTH);
        time.hour = calendar.get(Calendar.HOUR_OF_DAY);
        time.minute = calendar.get(Calendar.MINUTE);
        time.second = calendar.get(Calendar.SECOND);
        return time;
        // return calendar.get(Calendar.SECOND) + //
        // calendar.get(Calendar.MINUTE) * 60 + //
        // (calendar.get(Calendar.HOUR) + (calendar.get(Calendar.AM_PM) == 1 ?
        // 12 : 0)) * 3600;
    }
}
